<template>
  <div class="newsinfo-container">
    <h3 class="title">{{ newsinfoobj.title }}</h3>
    <p class="subtitle">
      <span>发表时间:{{ newsinfoobj.add_time | dateFormat }}</span>
      <span>点击次数:{{ newsinfoobj.click }}</span>
    </p>
    <hr />
    <div class="content" v-html="newsinfoobj.content"></div>
    <comment-box :id="this.id"></comment-box>
  </div>
</template>

<script>
import { Toast } from "mint-ui";

// 导入评论子组件
import comments from "../subcomponents/comments.vue";
export default {
  data() {
    return {
      // 将URL中传递来的id，挂载到data上，方便调用
      id: this.$route.params.id,
      newsinfoobj: {}
    };
  },
  created() {
    this.getnewsinfo();
  },
  methods: {
    getnewsinfo() {
      this.$http.get("api/getnew/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.newsinfoobj = result.body.message[0];
        } else {
          Toast("新闻获取失败");
        }
      });
    }
  },
  components: {
    //用来注册子组件
    "comment-box": comments
  }
};
</script>
<style lang="scss" scoped>
.newsinfo-container {
  padding: 0 4px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .subtitle {
    color: blue;
    display: flex;
    justify-content: space-between;
  }
}
</style>